/**
 * [283] 移动零
 *
 * @format
 * @lc app=leetcode.cn id=283 lang=javascript
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
// 双指针
var moveZeroes = function (nums) {
    let left = right =0
    while(right<nums.length){
        if(nums[right]){
            nums[left]+=nums[right]
            nums[right]=nums[left]-nums[right]
            nums[left]-=nums[right]
            left++
        }
    }
}
// 索引+长度记录
var moveZeroes = function (nums) {
    let i = (len = 0)
    while (i + len < nums.length) {
        if (nums[i + len] == 0) len++
        else ([nums[i], nums[i + len]] = [nums[i + len], nums[i]]), i++
    }
    // return nums
}
// @lc code=end
